Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework KeyPathArray filters for notifications in the C-API. #7087

Merged
merged 6 commits into from
Nov 23, 2023

Conversation

cmelchior
Copy link
Contributor

@cmelchior cmelchior commented Oct 27, 2023

This PR replaces the current way of using the KeyPathArray API in the C-API with an approach that moves more work to C++. So instead of looking up ClassKey/ColumnKeys in the SDK, this is instead done in a helper function in Core.

This means that SDKs just need to pass forward user input to Core and it will create the correct data structure.

Since no SDKs have exposed this through the C-API yet, this should be safe to break.

TODO:

  • Cleanup
  • Tests
  • Validate approach in Kotlin

@jedelbo
Copy link
Contributor

jedelbo commented Nov 10, 2023

@cmelchior should this be validated in Kotlin before merged?

Copy link

coveralls-official bot commented Nov 10, 2023

Pull Request Test Coverage Report for Build github_pull_request_285448

  • 151 of 155 (97.42%) changed or added relevant lines in 4 files are covered.
  • 158 unchanged lines in 19 files lost coverage.
  • Overall coverage decreased (-0.03%) to 91.669%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/realm/object-store/c_api/notifications.cpp 56 60 93.33%
Files with Coverage Reduction New Missed Lines %
src/realm/object-store/c_api/notifications.cpp 1 92.62%
src/realm/sync/noinst/client_impl_base.hpp 1 93.91%
src/realm/array_string.cpp 2 88.0%
src/realm/cluster.cpp 2 80.36%
src/realm/object-store/sync/sync_manager.cpp 2 86.9%
test/test_lang_bind_helper.cpp 2 93.3%
test/test_sync.cpp 2 94.14%
src/realm/sort_descriptor.cpp 3 93.7%
test/test_thread.cpp 3 66.67%
src/realm/sync/noinst/client_reset.cpp 4 93.49%
Totals Coverage Status
Change from base Build 1851: -0.03%
Covered Lines: 231353
Relevant Lines: 252379

💛 - Coveralls

@cmelchior
Copy link
Contributor Author

I'm finishing up the tests on Kotlin. So far, this seems to work, but I had to add support for backlinks pr. #7131. It feels a bit hacky though and like something is missing from the ObjectStore Schema APIs

@jedelbo jedelbo force-pushed the cm/rework-c-keypath-filtering branch from 9cfa503 to be45032 Compare November 17, 2023 13:00
@jedelbo
Copy link
Contributor

jedelbo commented Nov 17, 2023

I tries to update the col_key for computed properties during apply_schema_changes:

for (auto& property : object_schema.computed_properties) {
if (property.type == PropertyType::LinkingObjects) {
auto origin_table = ObjectStore::table_for_object_type(group, property.object_type);
auto origin_column_key = origin_table->get_column_key(property.link_origin_property_name);
property.column_key = origin_table->get_opposite_column(origin_column_key);
}
}

@tgoyne I am not sure if this is sufficient.

@tgoyne
Copy link
Member

tgoyne commented Nov 17, 2023

I don't see any obvious reason that won't work.

@cmelchior
Copy link
Contributor Author

Not 100% sure where the error is, but this doesn't work in Kotlin. Keypaths for normal Results work fine, but are broken for backlinks....Maybe the C-API creates the schema in a different way that doesn't end up hitting that codepath? 🤔

@cmelchior
Copy link
Contributor Author

Not 100% sure what is going on, but it looks like opening the same Realm multiple times will result inset_schema_keys only being called on the first Realm 🤔

@jedelbo jedelbo force-pushed the cm/rework-c-keypath-filtering branch from fce8171 to c0b6c00 Compare November 20, 2023 15:03
@cmelchior
Copy link
Contributor Author

I confirmed that this now works in Kotlin, so moving the PR to review. Not 100% sure who should review it though, since @jedelbo did most of the rewrite of the implementation?

@cmelchior cmelchior marked this pull request as ready for review November 21, 2023 08:33
@cmelchior cmelchior requested a review from jedelbo November 21, 2023 08:37
return ret;
}

static KeyPathArray create_key_path_array(Group& g, const ObjectSchema& object_schema, const Schema& schema,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't there be value in having this method available to SDKs that do not use the C-API? I guess it is already available since it is just a static helper method, but maybe the location is a bit wierd.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A static function is actually private within the compilation unit. We might consider making it public somewhere. At least to the binding generator.

@jedelbo jedelbo requested a review from nicola-cab November 21, 2023 13:52
Copy link
Member

@nicola-cab nicola-cab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM just 2 small suggestions

src/realm.h Outdated
*/
RLM_API realm_key_path_array_t* realm_create_key_path_array(const realm_t* realm,
const realm_class_key_t object_class_key,
int user_key_paths_count, const char** user_key_paths);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess user_key_paths_count cannot be negative.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure not.

@@ -361,6 +361,14 @@ constexpr inline size_t round_down(size_t p, size_t align)
return r & (~(align - 1));
}

// return pointer to found character or to terminating NUL
static inline const char* find_chr(const char* p, char c)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this utility? It seems to me that it is just a char *strchr(const char *string, int c);

Copy link
Contributor

@jedelbo jedelbo Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strchr will return nullptr if not found. We need it to return a pointer to terminating NUL character. GCC has a function called strchrnul, but that is not generally available.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I think it does not make a huge difference if we call strchr() and we check for nullptr in order to return a null terminated string or loop over like we do.

@jedelbo jedelbo merged commit 3bc7ce9 into master Nov 23, 2023
2 checks passed
@jedelbo jedelbo deleted the cm/rework-c-keypath-filtering branch November 23, 2023 09:42
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants